<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深拷贝</title>
</head>
<body>
    <script>
        // 使用JSON 转化的方式进行深拷贝，函数拷贝不了
        // 
        const school = {
            name:'atguigu',
            positions:['北京','上海','西安','深圳','武汉'],
            boss:{
                name:'刚哥',
                age:46
            },
            teach:function(){
                console.log('coding！');
            }
        }

        // 将对象转化成 JSON 字符串
        let jsonStr = JSON.stringify(school);
        // 在将JSON字符串还原成 对象就完成了深拷贝
        let target = JSON.parse(jsonStr);
        target.boss.name = '佟刚';
        target.positions[0] = 'beijing';
        console.log(target,school);
        
    </script>
</body>
</html>